#include "junix.h"

int main(int argc, char **argv)
{
	pid_t pid=fork();
	if(pid<0)
		err_sys("fork");

	if(!pid){
		pid_t pid2=fork();
		if( pid2<0 )
			err_sys("fork");
		if( !pid2){
			printf("Child:%d\n",getpid());
			sleep(4);
		}else{
			printf("Father:%d\n",getpid());
			sleep(2);
		}
	}else{
		int id;

		printf("Grandfather:%d\n",getpid());
		for(;;)	{
			if( (id=wait(NULL)) == -1)
				break;
			else 
				printf("(%d) exited\n",id);
		}
	}

    exit(0);
}

